package com.my.shiro.matcher;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;

public class MyCredentialsMatcher extends HashedCredentialsMatcher{
	
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        Object tokenHashedCredentials = hashProvidedCredentials(token, info);
        Object accountCredentials = info.getCredentials();
        return accountCredentials.equals(tokenHashedCredentials);
    }
	
	protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
       return DigestUtils.md5Hex(String.valueOf((char[])token.getCredentials()).getBytes());
    }

}
